//
//  DCPersonMsgTableViewCell.m
//  JiuyaoDriver
//
//  Created by 大橙子 on 2018/11/12.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCPersonMsgTableViewCell.h"
@interface DCPersonMsgTableViewCell ()

@end
@implementation DCPersonMsgTableViewCell
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *CellID = @"Cell";
    DCPersonMsgTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[DCPersonMsgTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI {
    self.titleLabel = [[UILabel alloc]init];
//    self.titleLabel.backgroundColor = [UIColor redColor];
    [self addSubview:self.titleLabel];
    
    self.subTextLabel = [[UILabel alloc]init];
//    self.subTextLabel.backgroundColor = [UIColor yellowColor];
    self.subTextLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.subTextLabel];
    
    UIButton *selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    selectedBtn.backgroundColor = RandomColor;
    [selectedBtn setTitleColor:BlueColor forState:UIControlStateNormal];
    [selectedBtn addTarget:self action:@selector(btnDidClick) forControlEvents:UIControlEventTouchUpInside];
    self.selectedBtn = selectedBtn;
    [self addSubview:selectedBtn];

}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleLabel.frame = CGRectMake(0, 0, self.width/3, self.height);
    if (self.isShowBtn) {
        self.selectedBtn.frame = CGRectMake(self.width - 60*WIDTHSCALE6, 0, 60*WIDTHSCALE6, self.height);
    }else{
        self.selectedBtn.frame = CGRectMake(self.width, 0, 0, self.height);
    }
    self.subTextLabel.frame = CGRectMake(self.width - self.width/2-5-self.selectedBtn.width, 0, self.width/2, self.height);

    
}
-(void)btnDidClick {
    if (self.block) {
        self.block();
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
